<?PHP
$PurviewLevel=0;
require("../../inc/common.inc.php");
require_once(dirname(__FILE__)."/../"."Admin_ChkPurview.php");
/**
*处理添加新消息
**/
if($action=="saveadd"){
if(intval($tuserid)==0){
	$fun->popmassage("参数错误","","popback");
	exit();
}
$appuserstr=$tuserid.",";
if ($ttitle=="" || empty($ttitle)){
	$fun->popmassage("信息标题不能为空","","popback");
	exit();
}
$ttype = intval($ttype);
$tsucaiid = intval($tsucaiid);

if($ttype==2){
	if($tcontent==""){
	$fun->popmassage("请设置消息的内容","","popback");
	exit();
	}
}else{
	if($tsucaiid==0){
	$fun->popmassage("请设置消息的内容","","popback");
	exit();
}
	
}
$addtime = mktime();
$truepath=preg_replace("/(.+)\/([^\/]+)\/([^\/]+)/is","\\1",'http://'.$HTTP_HOST.$PHP_SELF);
		
$db->excu("INSERT INTO `mx_tuisong_app` ( `ttitle`, `ttype`,`tsucaiid`,`tcontent`,`tuserids`,`addtime`,`addid`) VALUES ('$ttitle','$ttype','$tsucaiid','$tcontent','$appuserstr','$addtime','".$_SESSION['mxadmin']['userid']."')");
$tid = mysql_insert_id();

setcookie("appusers","",time()-3600);
setcookie("appusersnum","0",time()-3600);

if($appuserstr!=""){
	$appuserstr = substr($appuserstr,0,strlen($appuserstr)-1);
}

if($ttype!=2){
$sucaiinfo = $db->getinfo("select * from mx_sucai_app where aid ='$tsucaiid' limit 1");
if($ttype==1){
	$msg_content="url-:".$webdb["weburl"]."/".apppushurl."?id=".$tsucaiid;
}elseif($ttype==2){
	$msg_content="txt-:".$ttitle."：".$sucaiinfo["acontent"];	
}elseif($ttype==3){
	$msg_content="url-:".$sucaiinfo["aurl"];
}
}else{
	$msg_content="txt-:".$ttitle."：".$tcontent;	
}

$msg_conten1t = array("n_content"=>$msg_content,"n_extras"=>array("ios"=>array("badge"=>1)));
$msg_content1 = json_encode($msg_content1);
$platform1 = "ios";

$msg_content2 = array("message"=>$msg_content);
$msg_content2 = json_encode($msg_content2);
$platform2 = "android";

$obj = new jpush(masterSecret,appkeys);			 
$res1 = $obj->send($tid, 3, $appuserstr, 1, $msg_content1, $platform1);
$res2 = $obj->send($tid, 3, $appuserstr, 2, $msg_content2, $platform2);



if($res2["errcode"]==0&&$res2["errcode"]==0){
	$db->excu("update `mx_tuisong_app` set isok=1 where tid='$tid'");
}
jump2("操作成功","tuisong_app_list.php",2);
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>铭讯EOS网站后台管理</TITLE>
<Meta name="Keywords" Content="济南网站建设 济南网站制作 山东网站建设 济南铭讯软件有限公司">
<Meta name="Description" Content="济南网站制作：铭讯软件专业服务优秀企业，致力于网站建、设网站推广、网络营销一体的全访位网络服务商">
<link href="../images/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php require("../mx_head.php") ;?>

	<!--right-->
	<div class="right">
	  
		<div class="xm2">
			<h1 class="fl">APP信息</h1>
			<!--<span class="fr"><a href="#"><img src="../images/right_4.png" alt="设置" /></a></span>-->
			<div class="clear"></div>
		</div>
		<div class="xm2_b">
			<div class="height15"></div>
				<script type="text/javascript" src="../js/jquerys-1.5.1.js"></script>
                <script type="text/javascript" src="../js/pcasunzip.js"></script>
                <script type="text/javascript" src="../js/tuisong.js"></script>
				<script language="javascript">
				$(document).ready(function(){ //这个就是传说的ready   
				$(".stripe tr").mouseover(function(){   
				//如果鼠标移到class为stripe的表格的tr上时，执行函数   
				$(this).addClass("over");}).mouseout(function(){   
				//给这行添加class值为over，并且当鼠标一出该行时执行函数   
				$(this).removeClass("over");}) //移除该行的class   
				$(".stripe tr:even").addClass("alt");   
				//给class为stripe的表格的偶数行添加class值为alt
				//www.divcss5.com 整理特效
				});  
				function showinfo(returnid,changeid,changevalue){
					document.getElementById(changeid).value=changevalue;
					$.ajax({ url: "getinfo2.php?id="+changevalue+"&cid="+changeid,success: function(msg){
					  document.getElementById(returnid).innerHTML=msg;
					}});

					
				}
				var maxstrlen=140;
 
function Q(s){return document.getElementById(s);}
 
function checkWord(c){
 
len=maxstrlen;
 
var str = c.value;
 
myLen=getStrleng(str);
 
var wck=Q("wordCheck");
 
if(myLen>len*2){
 
c.value=str.substring(0,i+1);
 
}
 
else{
 
wck.innerHTML = Math.floor((len*2-myLen)/2);
 
}
 
}
 
function getStrleng(str){
 
myLen =0;
 
i=0;
 
for(;(i<str.length)&&(myLen<=maxstrlen*2);i++){
 
if(str.charCodeAt(i)>0&&str.charCodeAt(i)<128)
 
myLen++;
 
else
 
myLen+=2;
 
}
 
return myLen;
 
}
				function checkform(){
					var ttitle,ttype,tsucaiid,tmsgid;
					ttitle = document.form2.ttitle.value;
					ttype = document.form2.ttype.value;
					tsucaiid = document.form2.tsucaiid.value;
					tcontent = document.form2.tcontent.value;
					
					if(ttitle==""||ttitle=="请输入信息标题，字数20字以内"){
						alert("信息标题不能为空");
						document.form2.ttitle.focus();
						return false;
					}

					if(ttype==2){
						if(tcontent==""){
							alert("请设置消息的内容");
							return false;
						}
					}else{
						if(tsucaiid==0){
							alert("请设置消息的内容");
							return false;
						}
					}
					return true;
			    }
				
				</script>
				<form id="form2" name="form2" method="post" action="?action=saveadd" onsubmit="return checkform()">
                <input type="hidden" name="ttype" id="ttype" value="2">
                <input type="hidden" name="tsucaiid" id="tsucaiid" value="0">
                <input type="hidden" name="tuserid" id="tuserid" value="<?php echo $id;?>">
				  <table width="100%" border="0" align="left" cellpadding="9" cellspacing="0">
                    
                    
                    <tr>
                      <td align="right" class="font14">信息标题：</td>
                      <td colspan="2"><input type="text" name="ttitle" size="70" maxlength="20"  onFocus="if (this.value=='请输入信息标题，字数20字以内'){style.color='#000000';this.value='';}" onBlur="if (this.value==''){this.style.color='#cfcfcf';this.value='请输入信息标题，字数20字以内';}" value="请输入信息标题，字数20字以内" style="color:#cfcfcf; margin-top:1px;"/></td>
                    </tr>
                    <script>
					function switchmod(modtag,modtagclass1,modtagclass2,modk,modknum)
					{
						document.getElementById("ttype").value=modk;
						document.getElementById("tsucaiid").value=0;
						for(i=1; i <=modknum; i++)
						{
							content=modtag+"_list"+i;
							if (i==modk)
							{
							document.getElementById(modtag+i).className=modtagclass1;
							document.getElementById(content).style.display="block";
							}
							else
							{
							document.getElementById(modtag+i).className=modtagclass2;
							document.getElementById(content).style.display="none";
							}
							document.getElementById("list"+i).innerHTML="";
						}
					}
					
					</script>
                    <tr>
                      <td align="right" class="font14">信息类型：</td>
                      <td colspan="2">
                      <input type="button" class="button" value="文字" id="tab_2" onclick="switchmod('tab_','button','button2',2,3)">&nbsp;
                      <input type="button" class="button2" value="HTML" id="tab_1" onclick="switchmod('tab_','button','button2',1,3)">&nbsp;
                      <!--<input type="button" class="button2" value="文字" id="tab_2" onclick="switchmod('tab_','button','button2',2,3)">&nbsp;-->
                      <input type="button" class="button2" value="链接" id="tab_3" onclick="switchmod('tab_','button','button2',3,3)">
                      </td>
                    </tr>
                    <tr>
                      <td align="right" class="font14">&nbsp;</td>
                      <td colspan="2">
                       <style>
					  .tab_box{height:200px; width:80%;line-height:20px;padding:20px; border:#ccc 1px solid;-moz-border-radius:3px;/*仅Firefox支持，实现圆角效果*/-webkit-border-radius:3px;/*仅Safari,Chrome支持，实现圆角效果*/-khtml-border-radius:3px;/*仅Safari,Chrome支持，实现圆角效果*/border-radius:3px;/*仅Opera，Safari,Chrome支持，实现圆角效果*/ overflow-y:auto;}
					  .abutton{ height:30px; line-height:20px; padding-left:20px;}
					  </style>
                      <div id="tab__list1" style="display:none;">
                      <p class="abutton"><a href="javascript:showdiv('list1','tsucaiid','tuisong_appk_list','HTML信息')">点击选取HTML信息</a></p>
                      <div id="list1" class="tab_box">
                      </div>
                      </div>
                       <!--<div id="tab__list2" style="display:none;">
                      <p class="abutton"><a href="javascript:showdiv('list2','tsucaiid','tuisong_appk_list','文字信息')">点击选取文字信息</a></p>
                      <div id="list2" class="tab_box">
                      </div>
                      </div>-->
                      <div id="tab__list2">
                      <textarea name="tcontent" id="content" cols="70" rows="15" onKeyUp="javascript:checkWord(this);" onMouseDown="javascript:checkWord(this);"></textarea>
                      <p>还可以输入<span style="font-family: Georgia; font-size: 26px;" id="wordCheck">140</span>个字符</p>
                      <div id="list2" class="tab_box" style="display:none;">
                      </div>
                      </div>
                      <div id="tab__list3" style="display:none;">
                      <p class="abutton"><a href="javascript:showdiv('list3','tsucaiid','tuisong_appk_list','链接信息')">点击选取链接信息</a></p>
                      <div id="list3" class="tab_box">
                      </div>
                      </div>
                      
                      </td>
                    </tr>
                    
                    
                    <tr>
                      <td>&nbsp;</td>
                      <td class="font14" colspan="2"><input type="submit" class="button" name="button" id="button" value="完成" />&nbsp;&nbsp;
                      <input type="reset" class="button2" name="button2" id="button2" value="取消" /></td>
                    </tr>
                    <tr>
                      <td colspan="3" height="20">&nbsp;</td>
                    </tr>
                  </table>
          </form>
				<div class="height15"></div>
	  </div>
		<div class="clear"></div>
		<div class="height15"></div>
       
	  </div>
		<div class="clear"></div>
  <?php require("../mx_foot.php") ;?>
  </div>
	<!--right-end-->
</body>
</html>
